<template>
  <div>
    <login></login>
    <!--问卷-->
    <div class="block">
      <div class="title">{{ title }}</div>
      <div class="liveBroadcast" v-if="questionnaire">
        <img :src="questionnaire" height="100%" width="100%"/>
      </div>
      <div class="mainBody">
        <div class="explain">
          <button @click="participationQuestionnaire">参与问卷</button>
        </div>
        <div class="block2">
          <div class="introduce" v-if="description">
            <span>|</span>
            <span>问卷介绍</span>
          </div>
          <div class="text">{{ description }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//请求方法
import {api, httpPost, httpGet} from '../api/http.js'
//Base64
let Base64 = require('js-base64').Base64;

import login from '../element/login'

export default {
  components: {login},
  data() {
    return {
      title: '',
      questionnaire: '',
      description: '',
      obj: '',
    }
  },
  mounted() {
    this.obj = JSON.parse(Base64.decode(decodeURIComponent(window.location.href.split('?')[1])));
    this.getQuestionnairePage(this.obj.activityId)
  },
  methods: {
    getQuestionnairePage(activityId) {
      httpGet(api.getQuestionnairePage + activityId,).then((res) => {
        if (res.data.code == 200) {
          this.title = res.data.data.title
          if (res.data.data.bigImgUrl) {
            this.questionnaire = res.data.data.bigImgUrl
          } else {
            this.questionnaire = '../../static/img/问卷调查.jpg'
          }
          this.description = res.data.data.description
        }
      })
    },
    participationQuestionnaire() {
      httpGet(api.phone).then((res) => {
        if (res.data.code == 200) {
          httpGet(api.geturl + this.obj.activityId + '/' + res.data.data).then((res) => {
            if (res.data.code == 200) {
              window.location.href = res.data.data
            }
          })
        } else if (res.data.code == 50003) {
          this.$store.state.isActive = true
        }
      })
    },
  }
}
</script>

<style lang="less" scoped>
.block {
  font-family: PingFangSC;
  margin: 50px 25px;

  .title {
    font-size: 34px;
    font-weight: 800;
  }

  .liveBroadcast {
    width: 700px;
    margin: 20px 0;
  }

  .mainBody {
    font-weight: 400;
    font-style: normal;
    line-height: 46px;
    text-decoration: none;

    .explain {
      margin-bottom: -50px;
      height: 140px;

      button {
        width: 200px;
        height: 70px;
        z-index: 4;
        background-color: rgb(65, 128, 255);
        border: none;
        color: rgb(255, 255, 255);
        border-radius: 6px;
        font-size: 25px;
        text-align: center;
        font-weight: normal;
        font-style: normal;
        opacity: 1;
        float: right;
      }
    }

    .block2 {
      margin-bottom: 25px;

      .introduce {
        font-size: 25px;
        font-weight: 600;
        color: rgba(65, 128, 255, 1);
      }

      .text {
        font-size: 24px;
        margin-left: 20px;
      }
    }
  }
}
</style>
